<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>原型链继承</title>
    <script>
        /***
         * 
         */
        function Super() {
            this.superName = 'super'
        }
        
        Super.prototype.showSuper = function () {
            console.log(this.superName)
        }
        
        function Son() {
            this.sonName = 'son'
        }
        
        // 继承的关键，子类型的原型是父类型的实例对象
        Son.prototype = new Super()
        // 子类型的原型的构造函数指向子类型构造函数
        Son.prototype.constructor = Son

        Son.prototype.showSub = function () {
            console.log(this.sonName)
        }
        
        var son = new Son()
        son.showSub()
        son.showSuper()
        
        
        
        /**
         * 组合继承
         * 借用构造函数继承属性
         * 借助原型继承方法
         */
        function Animail(name, age) {
            this.name = name
            this.age = age
        }
        
        Animail.prototype.showAnimail = function () {
            console.log(this.name)
            console.log(this.age)
        }
        
        function Cat(name, age, price) {
            Animail.call(this, name, age) //继承属性
            this.price = price
        }
        
        Cat.prototype = new Animail()
        Cat.prototype.constructor = Cat
        
        Cat.prototype.showCat = function () {
            console.log(this.price)
        }
        
        var cat = new Cat('mimi',2,2000)
        console.log(cat)
        
        cat.showCat()
        cat.showAnimail()
        
        
        /**
         * 
         */
    </script>
</head>
<body>

</body>
</html>
